package com.hn.licenseverify.controller;

import de.schlichtherle.license.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.prefs.Preferences;

@RestController
@RequestMapping("/hello")
public class HelloController {

    @GetMapping
    public String hello(){
        return "hello word!";
    }

    static {
        Preferences pre = Preferences.systemRoot();
        CipherParam cipherParam = new DefaultCipherParam("zxy123456");
        KeyStoreParam pubStoreParam = new DefaultKeyStoreParam(HelloController.class, "/publicCerts.store", "publiccert1", "zxy123456", null);
        LicenseParam licenseParam = new DefaultLicenseParam("bigdata", pre, pubStoreParam, cipherParam);
        LicenseManager licenseManager = new LicenseManager(licenseParam);
        //校验失败停止jvm
        try {
            licenseManager.verify();
        } catch (Exception e) {
            System.exit(1);
        }
    }
}
